<?php
namespace Admin\Model;
use Think\Model;
    class OrdersModel extends Model{
        public function orders_sec(){
             // 得到总行数
            $totalRow = $this->count();
            // 每页显示条数
            $num = 10;
            // 实例化分页类
            $page = new \Think\Page($totalRow , $num);
            // 执行分页查询
            $list = $this->limit( $page->firstRow . ',' . $page->listRows )->select(); 
              //查询订单表数据，并返回给控制器
            // $list = $this->select();
             //设置订单状态
            $status = ['1'=>'未发货','2'=>'已发货','3'=>'无效订单','4'=>'订单完成'];
            foreach ($list as $key => &$value) {
                $value['status'] = $status[$value['status']];
                $value['addtime'] = date('Y-m-d H:i:s',$value['addtime']);
            }
            return [
                'list'=>$list,
                'show'=>$page->show()
            ];
        }
        //修改订单状态（发货）
        public function status_edit(){
            $id = I('get.id');
            $status = I('get.status');
            // 判断当前订单状态
            if($status == '未发货'){
                //执行修改--发货
                $map['id'] = ['eq',$id];
                $data['status'] = 2;
                $res = $this->where($map)->save($data);
                //---改变商品库存
                    //--获取订单商品id
                return $res;
            }else{
                return false;
            }
        }
        //搜索查询
        public function orders_like($orderid){
            // 设置查询条件
            $map['orderId'] = ['like',"%$orderid%"];
            //执行查询
            // return $map;
            $list = $this->where($map)->select();
            return ['list'=>$list];
        }
    }